package com.itheima.day13.thread.test9;

import java.util.concurrent.Callable;

public class TicketMyCallable implements Callable<String> {
    private int tickets = 1000;
    private Object obj = new Object();

    @Override
    public String call() throws Exception {
        while (true) {
            synchronized (obj) {
                if (tickets > 0) {
                    //Thread.sleep(5);
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + " 正在买票，还剩 " + tickets + " 张票。");
                } else {
                    break;
                }
            }
        }
        return null;
    }
}
